import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control


//新增


import MuseUI from 'muse-ui'
import 'muse-ui/dist/muse-ui.css'
import 'es6-promise/auto'

// 提示框
import msg from './utils/messages.js'
Vue.use(msg)
// 修改字段
import update from '@/utils/update.js'
Vue.prototype.update = update

//抽屉
import Drawer from '@/components/Drawer/Drawer'
Vue.component('drawer', Drawer)
import FormHead from '@/components/FormHead/FormHead'
Vue.component('form-head', FormHead)
import UploadPic  from "@/components/UploadPic/UploadPic";
Vue.component('upload-pic', UploadPic)
import PreView  from "@/components/UploadPic/PreView";
Vue.component('pre-view', PreView)

Vue.use(MuseUI)

//导入字体样式
import './assets/fonts/iconfont.css'
import './assets/iconfont/iconfont.css'

import { request, get } from '@/utils/request'

// Vue.prototype.$msg = msg
Vue.prototype.request = request
Vue.prototype.get = get
Vue.prototype.vue = Vue


Vue.prototype.get_upload_url =function(){
  if (process.env.VUE_APP_DEBUG) {
    return process.env.VUE_APP_BASE_API
  }else{
    return window.location.protocol + '//' + window.location.host+'/';
  }
} 
Vue.prototype.$setTagsViewTitle =function(id){
  if(id==0)return
  let tempRoute = Object.assign({}, this.$route)
  let title=this.$route.meta.title
  const route = Object.assign({}, tempRoute, { title: `${title}-${id}` })
  this.$store.dispatch('tagsView/updateVisitedView', route)
} 
Vue.prototype.$delTagsView =function(id){
  // if(id==0)return
  let tempRoute = Object.assign({}, this.$route)
  let title=this.$route.meta.title
  const route = Object.assign({}, tempRoute, { title: `${title}-${id}` })
 
  //加个保存过的路由数组,用来刷新表格
  if(id==0){
    this.$store.commit('user/SET_UPDATE_INDEX', route.name.replace('form','index'))
    console.log(this.$store.state.user.update_index)
  }
  this.$store.dispatch('tagsView/delView', route)
} 

import Print from 'vue-print-nb'
Vue.use(Print);  //注册


Vue.prototype.$back = function(id=0) {
  this.$delTagsView(id)
  this.$router.back()
}
//取是否刷新表格数据
Vue.prototype.$getUpdate = function() {
  return true
  let url= this.$route.name
  let i=this.$store.state.user.update_index.indexOf(url)
  if(i>=0){
    this.$store.commit('user/DEL_UPDATE_INDEX',i)
    return true
  }
  return false
}

Vue.prototype.isMobile = function() {
  return this.$store.state.app.device=='mobile'
}


//新增结束

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  store,
  router,
  Drawer,
  render: h => h(App)
})
